﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace GreatGF
{
    public partial class CALIB_CONFIG_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    CALIB_CONFIG_BLL m_CALIB_CONFIG_BLL = new CALIB_CONFIG_BLL();

                    if(m_CALIB_CONFIG_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        CALIB_CONFIG m_CALIB_CONFIG = new CALIB_CONFIG();
                        m_CALIB_CONFIG = m_CALIB_CONFIG_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_CALIB_CONFIG.ID.ToString();
                        txtJCXH.Text = m_CALIB_CONFIG.JCXH;
                        txtDevID.Text = m_CALIB_CONFIG.DevID;
                        txtDevName.Text = m_CALIB_CONFIG.DevName;
                        txtBDZQ.Text = m_CALIB_CONFIG.BDZQ;
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "CALIB_CONFIG_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtJCXH.ReadOnly = true;
                        txtJCXH.CssClass = "csstextboxreadonly";
                        txtDevID.ReadOnly = true;
                        txtDevID.CssClass = "csstextboxreadonly";
                        txtDevName.ReadOnly = true;
                        txtDevName.CssClass = "csstextboxreadonly";
                        txtBDZQ.ReadOnly = true;
                        txtBDZQ.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='CALIB_CONFIG_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strJCXH = txtJCXH.Text.Trim();
            string strDevID = txtDevID.Text.Trim();
            string strDevName = txtDevName.Text.Trim();
            string strBDZQ = txtBDZQ.Text.Trim();


            CALIB_CONFIG m_CALIB_CONFIG = new CALIB_CONFIG();
            CALIB_CONFIG_BLL m_CALIB_CONFIG_BLL = new CALIB_CONFIG_BLL();

            m_CALIB_CONFIG.JCXH = strJCXH;
            m_CALIB_CONFIG.DevID = strDevID;
            m_CALIB_CONFIG.DevName = strDevName;
            m_CALIB_CONFIG.BDZQ = strBDZQ;

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_CALIB_CONFIG_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                //m_CALIB_CONFIG.ID = m_CALIB_CONFIG_BLL.GetMax_ID();

                if (m_CALIB_CONFIG_BLL.Insert(m_CALIB_CONFIG) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_CALIB_CONFIG.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_CALIB_CONFIG_BLL.Update(m_CALIB_CONFIG, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
